package com.appkubes.mall.admin.application.user.account.withdraw.controller;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.user.account.withdraw.entity.vo.AccountWithdrawVO;
import com.appkubes.mall.admin.application.user.account.withdraw.entity.vo.WithdrawPassVO;
import com.appkubes.mall.admin.application.user.account.withdraw.service.AccountWithdrawService;
import com.appkubes.mall.core.common.constants.MallUserAccountWithdrawConstants;
import com.appkubes.mall.core.controller.BaseMallUserAccountWithdrawController;
import com.appkubes.mall.core.entity.MallUserAccountWithdraw;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@Api(tags = "用户提现列表")
@RestController
@RequestMapping("/account/withdraw")
public class UserAccountWithdrawController extends BaseMallUserAccountWithdrawController {

    @Resource
    AccountWithdrawService accountWithdrawService;

    @ApiOperation("通过提现")
    @GetMapping("/pass")
    public Response pass(@ParamValid WithdrawPassVO withdrawPassVO) {
        MallUserAccountWithdraw withdraw = accountWithdrawService.getById(withdrawPassVO.getKey());
        withdraw.setState(MallUserAccountWithdrawConstants.State.PROCESSED.name());
        withdraw.setUpdateTime(new Date());
        Boolean flag = accountWithdrawService.updateById(withdraw);
        return Response.success(flag);
    }

    @ApiOperation("提现列表")
    @GetMapping("/getList")
    public Response<IPage<MallUserAccountWithdraw>> getList(@ParamValid AccountWithdrawVO accountWithdrawVO) {
        IPage<MallUserAccountWithdraw> mallUserAccountWithdrawList = accountWithdrawService.getList(accountWithdrawVO);
        return Response.success(mallUserAccountWithdrawList);
    }
}
